package com.fyt.reachgo.config;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class ChatClientConfig {

    final OllamaChatModel model;
    @Bean
    public ChatClient ChatClient() {
        return ChatClient.builder(model)
                // 是否记忆上下文
                .defaultAdvisors(new MessageChatMemoryAdvisor(getChatMemory()))
                .defaultSystem("你是一名熟悉各自旅游路线的资深导游,现在以专业且接地气的语言为用户解答")
                .build();
    }

    /**
     * 实现上下文记忆
     * @return
     */
    @Bean
    public ChatMemory getChatMemory() {

        // 负责存和读
        return new InMemoryChatMemory();
    }
}
